package com.common.android.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.nd.android.u.allcommon.R;

/**
 * ClassName:LoadingImageView
 * Function: 自定义的“加载中”控件
 * Reason:	 
 * @author   cb		
 * @version  Ver 1.0.0
 * @Date	 2014	2014-4-9		4:29:57
 *
 * @see 	 
 */
public class LoadingImageView extends ImageView {
	private Animation mAnimation;
	public LoadingImageView(Context context) {
		super(context);
		init(context);
	}
	
	public LoadingImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	public LoadingImageView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}
	
	private void init(Context context) {
		setBackgroundResource(R.drawable.common_icon_loading);
		mAnimation=AnimationUtils.loadAnimation(context, R.anim.loading);
		startAnimation(mAnimation);
	}
	
	public void setLoadingIcon(int resid){
		setBackgroundResource(resid);
	}
	
	@Override
	public void setVisibility(int visibility) {
		super.setVisibility(visibility);
		if (visibility==View.VISIBLE){
			startAnimation(mAnimation);
		}else{
			//不可见的时候要移除动画，否则还能看到控件
			setAnimation(null);
		}
	}
}
